<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\AuthController;
use App\Http\Controllers\ProductController;
use App\Http\Controllers\ProductImageController;
use App\Http\Controllers\CategoryController;


/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/


// 公共路由（不需要认证）
Route::post('/register', [AuthController::class, 'register']);
Route::post('/login', [AuthController::class, 'login']);

// 认证路由（需要有效的 Sanctum Token）
Route::middleware(['api', 'cors', 'permission'])->group(function () { // <-- 这一行应用中间件
    Route::get('/user', [AuthController::class, 'user']);
    Route::post('/logout', [AuthController::class, 'logout']);

    // ... 其他受保护的 API 端点
    Route::post('/product/add', [ProductController::class, 'add']);
    Route::post('/product_image/add', [ProductImageController::class, 'add']);
    Route::post('/category/add', [CategoryController::class, 'add']);
});